for ww in $(seq 0 7003); 
do 
    ii=$(printf %04d $ww)
    ss=$(echo *n$ii.sh)
    rr=AnaOut_sub$ii.root; 

    #echo checking $ii ...
    
    if [ -e $ss ];
    then 
        if [ ! -e $rr ]; 
        then
            echo "======================= resubmitting $ss $rr ..."; 

            jobfile=$ss

            qsub -l cput=00:10:00 -N $jobfile  ./$jobfile 
            
            nq=$(qstat | grep $(whoami) | grep Q |wc | awk '{print $1}' )
            while [ $nq -gt 10 ]
            do
                sleep 10
                nq=$(qstat | grep $(whoami) | grep Q |wc | awk '{print $1}' )
            done

        fi; 
    fi;
done 
